package xjh.him.common;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CustomFuture<T> {
    private static final CyclicBarrier barrier = new CyclicBarrier(2);
    private T t;

    public void complete(T obj) {
        t = obj;
        try {
            barrier.await();
        } catch (BrokenBarrierException | InterruptedException e) {
            e.printStackTrace();
        }
    }

    public T get() {
        try {
            barrier.await();
        } catch (BrokenBarrierException | InterruptedException e) {
            e.printStackTrace();
        }
        barrier.reset();
        return t;
    }
}
